<?php
/**
 *  @author xuanhoapro <xuanhoapro@gmail.com>
 *  @version  1.0
 *  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
if (!defined('_CAN_LOAD_FILES_'))
    exit;

class XHUploadConcept extends Module
{	
	const INSTALL_SQL_FILE = 'install.sql';	
	private $_html = '';
	private $_postErrors = array();
	private $_baseUrl;
	
	function __construct()
	{
		$this->name = 'xhuploadconcept';	
		$this->version = '1.0';
		$this->tab = 'front_office_features';
		$this->author = 'xuanhoapro@gmail';
		$this->displayName = $this->l('Upload concept module');	
		$this->description = $this->l('Module that allows webshop Customers to upload files (doc,jpg) in the front office main page.');
		$this->confirmUninstall = $this->l('Are you sure you want to delete your details?');
		$this->need_instance = 0;
		$this->secure_key = Tools::encrypt($this->name);
		parent::__construct();		
	}
	
	/**
	 * Install
	 *
	 * @return boolean
	 */
	function install()
	{
		/*Install sql*/
		if ((!file_exists(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE)) 
		 || (!$sql = file_get_contents(dirname(__FILE__).'/'.self::INSTALL_SQL_FILE)))
			return false;
		$sql = str_replace(array('PREFIX_', 'ENGINE_TYPE'), array(_DB_PREFIX_, _MYSQL_ENGINE_), $sql);
		$sql = preg_split("/;\s*[\r\n]+/", $sql);
		foreach ($sql AS $query)
			if (!Db::getInstance()->Execute(trim($query)))
				return false;
		
		if (!parent::install()
            OR !$this->registerHook('header')
		    OR !$this->registerHook('home')
		)
			return false;	

		return true;
	}
	
	/**
	 * UnInstall
	 * 
	 * @return boolean
	 */
	public function uninstall()
	{  
		if (!Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'concept`')
		 OR !Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'concept_file`')
		 OR !Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'customer_credit`')
		)
			return false;
			
		if (!parent::uninstall())
			return false;	
			
		return true;
	}

/*========================= Hook =======================================
    /**
     * Hook frontOffice product tab content
     */
    public function hookHeader()
    {
        global $cookie, $smarty;
        if ($cookie->isLogged()){
            $smarty->assign(array(
                '_path' => $this->_path,
            ));
            return ($this->display(__FILE__, 'views/header.tpl'));
        }
    }
    /**
	 * Hook frontOffice product tab content
     */
    public function hookHome()
    {
    	global $cookie, $smarty;
        if ($cookie->isLogged()){
            $smarty->assign(array(
                '_path' => $this->_path,
            ));
            return ($this->display(__FILE__, 'views/home.tpl'));
        }
    }
	
	
	
}
?>